﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MES_SystemUI;
using MES_SystemUI.Context;
using MES_SystemUI.Domain;
using MES_SystemUI.Helpers;

namespace test
{
    public partial class Form1 : Form
    {
        static string KeyStr;
        static string IVStr;
        public Form1()
        {
            InitializeComponent();
            KeyStr = "1234567812345678";
            IVStr  = "1234567812345678";
            button1.Enabled = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MES_SystemUI.Context.MES_SystemContext context = new MES_SystemUI.Context.MES_SystemContext();
            context.users.Add(new User()
            {
                UserName = "test",
                Password = MES_SystemUI.Helpers.EncryptionAndDecryption.Encrypt("test", KeyStr, IVStr),
                Phone ="12312312312",
                CreateUserId = 1,
            });
            button1.Enabled = false;
            context.SaveChanges();
            context.Dispose();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Console.WriteLine();
            Console.WriteLine(MES_SystemUI.Helpers.EncryptionAndDecryption.Encrypt("server=.;database=MES_System;uid=sa;pwd=123456;", KeyStr, IVStr));
            Console.WriteLine();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Console.WriteLine(MES_SystemUI.Helpers.EncryptionAndDecryption.Decrypt(ConfigurationManager.ConnectionStrings["EMS_System"].ConnectionString, KeyStr, IVStr));
        }
        // 添加产品类型
        private void button3_Click_1(object sender, EventArgs e)
        {
            using (var c = new MES_SystemUI.Context.MES_SystemContext())
            {
                MES_SystemUI.Domain.ProductCategorie mode = new ProductCategorie()
                {
                    ProductCategoryName = "类型A",
                    CreateUserId =1,
                };
                c.Entry(mode).State = System.Data.Entity.EntityState.Added;
                c.SaveChanges();

            }
        }
    }
}
